########################################
#makefile
########################################
#编译指定子目录
SUBDIRS := .\\lib\\NC_Com\
		   .\\lib\\NC_FileSys\
           .\\lib\\NC_BlkFile\
           .\\lib\\NC_Card\\NC_Card_Lib\
           .\\lib\\NC_UPCash\\NC_UPCash_Lib

define make_subdir
 @ for subdir in $(SUBDIRS) ; do \
 ( cd $$subdir && make $1) \
 done;
endef

#编译主程序
BINARY  := ./bin/bus
OBJ_DIR := ./obj/
CC= gcc
LD= ld
CFLAGS= -std=c99 -Wall -g
LDSCRIPT= -lmycom -lws2_32 -liconv -lmyfile  -lmycard -lmyup -lmycalc -lmyblkfile -llua
LDFLAGS= -Llib 

SRC  = $(wildcard *.c)
DIR  = $(notdir $(SRC))
OBJS = $(patsubst %.c,$(OBJ_DIR)%.o,$(DIR))
#OBJS=  main.o myutils.o  inirw.o  cmdpboc.o cputest.o bustcp.o ansrec.o m1cmd.o m1api.o m1test.o upcash.o myother.o getsys.o
#CFLAGS=-std=c99
#@echo Building lib...
#$(call make_subdir)
.PHONY: clean lib
all:  prebuild  $(BINARY).exe

prebuild:
	@echo Building app...

$(BINARY).exe : $(OBJS)
	@echo Generating ...
	$(CC) -o $(BINARY).exe $(OBJS) $(LDFLAGS) $(LDSCRIPT) 
	@echo OK!

$(OBJ_DIR)%.o : %.c
	$(CC) -c $(CFLAGS) $< -o  $@
	
lib:
	@echo Building lib...
	$(call make_subdir)
	
clean:
	rm -f $(OBJ_DIR)*.o
	@echo Removed!